package com.cqfae.deploycentral.app.web.controller;

import com.cqfae.deploycentral.app.dao.mapper.ApproveDocumentMapper;
import com.cqfae.deploycentral.app.services.CommonControllerService;
import com.cqfae.deploycentral.app.services.ConstantsCodeService;
import com.cqfae.deploycentral.app.services.ExpectPublishEnqueueService;
import com.cqfae.deploycentral.app.services.JiraService;
import com.cqfae.deploycentral.app.utils.NullUtil;
import com.cqfae.deploycentral.app.web.request.ConstantsCodeRequest;
import com.cqfae.deploycentral.app.web.request.ReportInfoRequest;
import com.cqfae.deploycentral.app.web.response.WebResponse;
import com.cqfae.deploycentral.app.web.vo.SelectedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/deploy-central/jira")
public class JIRAController implements CommonControllerService<Object> {

    @Autowired
    private JiraService jiraService;
    @Autowired
    private ConstantsCodeService constantsCodeService;
    @Autowired
    private ApproveDocumentMapper approveDocumentMapper;
    @Autowired
    private ExpectPublishEnqueueService expectPublishEnqueueService;

    /**
     * 查询所有需要审批的项目信息
     * @return WebResponse
     */
    @RequestMapping(value = "/ExceptAppInfo")
    public WebResponse pageInfo(){
        return getWebResponse(jiraService.getReadyForReleasedVersionToApprove());
    }

    /**
     * 根据测试报告编号拼接对应的JIRA的版本信息
     * @return
     */
    @RequestMapping(value = "/appendJiraInfo")
    public WebResponse appendJiraInfo(ReportInfoRequest request) {
        return getWebResponse(expectPublishEnqueueService.appendJiraInfo(request.getReportCode()));
    }

    /**
     * 获取当前JIRA项目组的信息
     * @return
     */
    @RequestMapping(value = "/getJIRAProjectInfo")
    public WebResponse getJIRAProjectInfo(){
        ConstantsCodeRequest request = new ConstantsCodeRequest();
        request.setParentCode("projectName");
        List<SelectedVo> selectedVos = constantsCodeService.getInfoByParentCode(request);
        return getWebResponse(selectedVos);
    }


    @Override
    public WebResponse getWebResponse(Object obj) {
        WebResponse webResponse = new WebResponse();
        if (NullUtil.isNotEmpty(obj)) {
            webResponse.setData(obj);
        }
        return webResponse;
    }
}
